package ch.bfh.swos.learnaid.service;

import javax.inject.Inject;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import ch.bfh.swos.learnaid.service.dto.AnswerDTO;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/serviceContext.xml")
public class AnswerServiceIT {
    
    @Inject
    private AnswerService answerService;

    @Test
    public void test() {
        // Create
        AnswerDTO newAnswer = new AnswerDTO();
        newAnswer.setText("Answertext");
        newAnswer = answerService.create(newAnswer);

        // Read
        AnswerDTO readAnswer = answerService.read(newAnswer.getId());
        Assert.assertTrue(newAnswer.getText().equals(readAnswer.getText()));
        
        // Update
        readAnswer.setText("Test2");
        readAnswer = answerService.update(readAnswer);
        AnswerDTO updatedAnswer= answerService.read(readAnswer.getId());
        Assert.assertTrue(readAnswer.getText().equals(updatedAnswer.getText()));

        // Delete
        answerService.delete(updatedAnswer);
        AnswerDTO deletedAnswer = answerService.read(updatedAnswer.getId());
        Assert.assertNull(deletedAnswer);
    }

}
